import tensorflow as tf
import numpy as np
import sys
data = np.load("../../npz/120K_Cax+C7.npz")

modelfolder = sys.argv[1]
inputname = "X:0"
outputname = "z_x:0"

sess = tf.Session()

tf.saved_model.loader.load(sess, ['serve'], modelfolder)
graph = tf.get_default_graph()
phX = graph.get_tensor_by_name(inputname)
phz = graph.get_tensor_by_name(outputname)

allx = data['xyz']
print("allx", allx.shape)
case = len(allx)
indx = np.random.permutation(case)
printx=[]
printz= []
with open("init.log", "w+") as fout:
    for i in range(1000):
        x = allx[indx[i]]
        z = sess.run(phz, feed_dict={phX: x.reshape([1, -1])})
        print(i, data['label'][indx[i]], file=fout)
        # print(z[0][0], x[0], x[1], x[2], x[3], x[4])
        # print(z[0][0], x[0], x[1], x[2], x[3], x[4], file=fout)
        print(i, x.shape)
        printx += [x]
        printz += [z]
printx = np.vstack(printx)
printz = np.hstack(printz).reshape([-1, 1])
print(np.min(printz), np.max(printz))
print(printx.shape)
np.savez("init_config.npz", xyz=printx, z=printz)

